
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.io.InputStreamReader"%>
<%@page import="java.io.BufferedReader"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Date"%>
<%@page import="com.openbravo.data.loader.BatchSentenceResource"%>
<%@page import="com.openbravo.data.basic.BasicException"%>
<%@page import="com.openbravo.pos.base.AppLocal"%>
<%@page import="cn.ekuma.epos.datalogic.I_DataLogicSales"%>
<%@page import="java.util.regex.Matcher"%>
<%@page import="net.xeoh.plugins.base.PluginManager"%>
<%@page import="com.openbravo.data.loader.BatchSentence"%>
<%@page import="net.xeoh.plugins.base.impl.PluginManagerFactory"%>
<%@page import="cn.ekuma.epos.datalogic.define.DataLogicSales"%>
<%@page import="com.openbravo.data.loader.Session"%>
<%@page import="com.openbravo.data.loader.I_Session"%>
<%@page import="com.openbravo.pos.util.StringUtils"%>
<%@page import="com.openbravo.bean.Product"%>


<%
//String driver = application.getInitParameter ("driver");//读取数据库驱动
String url = application.getInitParameter("db.URL");           //读取URL
String user = application.getInitParameter("db.user");       //读取用户名
String password = application.getInitParameter("db.password");   //读取密码


	boolean isInstall = true;
	String method = request.getMethod();
	String ctx = request.getContextPath();
	String msg = "";
	
	Session s=new Session(url,user,password);
	
	I_DataLogicSales dlSales = new DataLogicSales(s,null,null);
	request.setCharacterEncoding("utf-8");
	// 提交安装数据
	if ("POST".equalsIgnoreCase(method)) {
		
		String code = request.getParameter("code");
		String name = request.getParameter("name");
		String costPrice = request.getParameter("costPrice");
		String sellPrice = request.getParameter("sellPrice");
		String custPrice = request.getParameter("custPrice");
		if (code!=null&&!code.isEmpty()
				&& name!=null&&!name.isEmpty()
				&& costPrice!=null&&!costPrice.isEmpty()
				&& sellPrice!=null&&!sellPrice.isEmpty()){
			Product p=new Product();
			p.setReference(String.valueOf(new Date().getTime()));
			p.setCode(code);
			p.setCategoryID("000");
			p.setName(name);
			p.setPriceBuy(Double.valueOf(costPrice));
			p.setPriceSell(Double.valueOf(sellPrice));
			if(custPrice!=null&&!custPrice.isEmpty())
				p.setM_dCustomerPrice(Double.valueOf(custPrice));
			p.setTaxCategoryID("000");
			p.setCurDate(new Date());
			p.setLastModified(new Date());
			try{
			dlSales.insert(p);
			msg="保存成功";
			}catch (Exception e){
				msg=e.getMessage();
			}
			
		}else {
			msg = "必须填写正确!";
	    }
	}
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新增商品资料</title>
<link rel="stylesheet" type="text/css" href="<%=ctx%>/themes/admin/style/admin.css" />
</head>
<body>
	<center>
	<div id="header-wrapper">
		<div id="header">
			<div id="admin-title" class="left">
				<span class="small">简单的, 高效的</span>
			</div>
			<div id="admin-func" class="right">
			</div>
			<div class="clear"></div>
		</div>
	</div>
	<div id="content-wrapper">

	<%=msg %>
	<form action="" method="post" onsubmit="return confirm('确定吗?')">
	<br>
	<table width="720" class="listt">
		<tbody>
			<tr>
				<td width="150" align="right">条码</td>
				<td><input type="text" name="code" class="shadowfocus" value="1234567890"></td>
			</tr>
			
			<tr>
				<td width="150" align="right">商品名称</td>
				<td><input type="text" name="name" class="shadowfocus" value="爱记录,爱分享,爱生活!"></td>
			</tr>
			
			<tr>
				<td width="150" align="right">进价</td>
				<td><input type="text" name="costPrice" class="shadowfocus" value=""></td>
			</tr>
			
			<tr>
				<td width="150" align="right">售价</td>
				<td><input type="text" name="sellPrice" class="shadowfocus" value=""></td>
			</tr>
			
			<tr>
				<td width="150" align="right">会员价</td>
				<td><input type="text" name="custPrice" class="shadowfocus" value=""></td>
			</tr>
		</tbody>
	</table>
	<br>
	
	<input type="submit" class="btn2 shadowhover2" value="增加">
	
	</form>
</center>
	</div> <!-- end content-wrapper -->
	<div id="footer">
	</div>
	
	<style>
		input[type=text], textarea {
			width: 400px;
		}
		textarea {
			height: 100px;
		}
		td {
			padding: 30px;
		}
	</style>
</body>
</html>